namespace KinonekoSoftware.CodariaDB.Documents.Composites
{
    partial class CompositeEngine
    {
        
        public IEnumerable<Birthday> GetBirthdays() => BirthdayDB.FindAll();

        public void AddOrUpdateBirthday(string id, int month, int day)
        {
            var birthday = BirthdayDB.FindById(id);

            if (birthday is null)
            {
                birthday = new Birthday
                {
                    Id    = id,
                    Month = month,
                    Day   = day,
                };
                BirthdayDB.Insert(birthday);
                Modified();
            }
            else if(month != birthday.Month || day != birthday.Day)
            {
                birthday.Month = month;
                birthday.Day   = day;
                BirthdayDB.Update(birthday);
                Modified();
            }
        }

        public void RemoveBirthday(string id)
        {
            BirthdayDB.Delete(id);
            Modified();
        }

    }
}